//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package SaveServlet.student;

import com.lyq.bean.Student;
import com.lyq.bean.service.S_Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(
        name = "RemoveStudent_Servlet",
        urlPatterns = {"/RemoveStudent_Servlet"}
)
public class RemoveStudent_Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RemoveStudent_Servlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String elect = request.getParameter("id");
        if (elect.equals("seekall")) {
            List<Student> list = new ArrayList();
           list = (new S_Service()).seekAll_S(list);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/jsp/student/m/RemoveStudent.jsp").forward(request, response);
        } else if (elect.equals("remove")) {
            String No = request.getParameter("No");
            Boolean bool = (new S_Service()).remove_S(No);
            if (bool) {
                request.getSession().setAttribute("message", "删除成功！");
            } else {
                request.getSession().setAttribute("message", "删除失败！");
            }

            request.getSession().setAttribute("url", "RemoveStudent_Servlet?id=seekall");
            response.sendRedirect("Message.jsp");
        }

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String select = request.getParameter("select");
        String seek = request.getParameter("seek");
        String name = request.getParameter("name");
        if (name != null || name == "") {
            List<Student> list = new ArrayList();
            list = (new S_Service()).seek_S(select, seek, name, list);
            request.setAttribute("list", list);
            if (list.size() >= 1 && list != null) {
                request.getRequestDispatcher("/jsp/student/m/RemoveStudent.jsp").forward(request, response);
            }
             else {
                request.getSession().setAttribute("message", "未找到你要查询的内容！");
                request.getSession().setAttribute("url", "RemoveStudent_Servlet?id=seekall");
                response.sendRedirect("Message.jsp");
            }
        }
        else{
            //输出所有学生信息
            List<Student> list = new ArrayList();
            list = (new S_Service()).seekAll_S(list);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/jsp/student/m/RemoveStudent.jsp").forward(request, response);
        }

    }
}
